#ifndef __COMMAND_H__
#define __COMMAND_H__
#define PATHSTACK_MAXSIZE 1024
#define PATHNAME_MAXLEN 50
#define BUFSIZE 4096
#include "../server/head.h"
#include <syslog.h>
#include <errno.h>
// 检错，输出到日志
#define LOG_ERRORCHECK(ret,err_flag,msg)\
    do{\
        if(ret == err_flag){\
            syslog(LOG_ERR,"log>%s: %s\n",msg,strerror(errno));\
        }\
    }while(0)
// 记录警告信息
#define LOG_WARNING_RECORD(msg)\
    do{\
        syslog(LOG_WARNING,"log>%s\n",msg);\
    }while(0)
// 记录操作和时间
#define LOG_INFO_RECORD(msg)\
    do{\
        time_t timeNow=time(NULL);\
        char buf[100] = {0};\
        syslog(LOG_INFO,"log>%s: %s\n",ctime_r(&timeNow,buf),msg);\
    }while(0)


typedef struct pathStack_s{
    char* pathArr[PATHSTACK_MAXSIZE];
    int top;// 栈顶指针，为-1时表示为空
    int rootPathPointer;// 指向客户端眼里“根目录”的位置，top==rootPathPointer时，不允许再cd ..
}pathStack_t;
int pathStackInit(pathStack_t* pathStack);
int curPathInit(pathStack_t* pCurPathStack, char* rootPath);
int popStack(pathStack_t* pathStack);
int pushStack(pathStack_t* pathStack,const char * str);
int saveStrPathToStack(char*path,pathStack_t* pathStack);
int getPath(const pathStack_t* pathStack,char* result);
int isDir(char *path);


int my_cd(char *path, pathStack_t *pCurpathStack);
int my_ls(char *path, pathStack_t *pCurpathStack, char *result);
int my_rmFile(char *fileName, pathStack_t *pCurpathStack);
int my_pwd(pathStack_t* pCurPathStack,char * result);
int my_mkdir(char *dirName, pathStack_t *pCurpathStack);
int my_rmdir(char *dirName, pathStack_t *pCurpathStack);
#endif
